/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyectos.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Jose
 */
@Entity
@Table(name = "Matriculas")
@NamedQueries({
    @NamedQuery(name = "Matriculas.findActiveDir", query = "SELECT m FROM Matriculas m  where  m.ncarrera = :ncarrera and m.ncurso  = :ncurso and m.nproyecto is not null and m.ndirector = :ndirector and (m.nalumno.cnombre like :cnombre or m.nalumno.capellidos like :cnombre)"),        
    @NamedQuery(name = "Matriculas.findActive", query = "SELECT m FROM Matriculas m  where  m.ncarrera = :ncarrera and m.ncurso  = :ncurso and m.nproyecto is not null and m.ndirector is not null and (m.nalumno.cnombre like :cnombre or m.nalumno.capellidos like :cnombre)"),    
    @NamedQuery(name = "Matriculas.findAll", query = "SELECT m FROM Matriculas m  where  m.ncarrera = :ncarrera and m.ncurso  = :ncurso and (m.nalumno.cnombre like :nalumno or m.nalumno.capellidos like :nalumno) and m.nproyecto is null"),
    @NamedQuery(name = "Matriculas.findAllPro", query = "SELECT m FROM Matriculas m  where  m.ncarrera = :ncarrera and m.ncurso  = :ncurso and m.nproyecto is not null and m.ndirector is null and (m.nalumno.cnombre like :cnombre or m.nalumno.capellidos like :cnombre)"),
    // @NamedQuery(name = "Matriculas.findAllPro2", query = "SELECT m FROM Matriculas m  where  m.ncarrera = :ncarrera and m.ncurso  = :ncurso and m.nproyecto is not null and m.ndirector is null and (m.nalumno.cnombre like :nalumno or m.nalumno.capellidos like :nalumno)"),
    @NamedQuery(name = "Matriculas.findByUk", query = "SELECT m FROM Matriculas m where m.ncarrera = :ncarrera and m.ncurso  = :ncurso and m.nalumno = :nalumno"),
    @NamedQuery(name = "Matriculas.findByUkPro", query = "SELECT m FROM Matriculas m where m.ncarrera = :ncarrera and m.ncurso  = :ncurso and m.nalumno = :nalumno and m.nproyecto is null")
})
public class Matriculas implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column
    private BigDecimal ncodigo;
    @ManyToOne
    @JoinColumn(name = "ncarrera")
    private Carreras ncarrera;
    @ManyToOne
    @JoinColumn(name = "nproyecto")
    private Proyectos nproyecto;
    @ManyToOne
    @JoinColumn(name = "ndirector")
    private Directores ndirector;
    @ManyToOne
    @JoinColumn(name = "ncurso")
    private Cursos ncurso;
    @ManyToOne
    @JoinColumn(name = "nalumno")
    private alumnos nalumno;
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "nmatricula", orphanRemoval = true)
    private List<HitosMatricula> vhitos;

    public List<HitosMatricula> getVhitos() {
        if (vhitos == null) {
            vhitos = new ArrayList<HitosMatricula>();
        }
        return vhitos;
    }

    public void setVhitos(List<HitosMatricula> vhitos) {
        this.vhitos = vhitos;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Matriculas other = (Matriculas) obj;
        if (!Objects.equals(this.ncarrera, other.ncarrera)) {
            return false;
        }
        if (!Objects.equals(this.ncurso, other.ncurso)) {
            return false;
        }
        if (!Objects.equals(this.nalumno, other.nalumno)) {
            return false;
        }
        return true;
    }

    public BigDecimal getNcodigo() {
        return ncodigo;
    }

    public void setNcodigo(BigDecimal ncodigo) {
        this.ncodigo = ncodigo;
    }

    public Carreras getNcarrera() {
        return ncarrera;
    }

    public void setNcarrera(Carreras ncarrera) {
        this.ncarrera = ncarrera;
    }

    public Cursos getNcurso() {
        return ncurso;
    }

    public void setNcurso(Cursos ncurso) {
        this.ncurso = ncurso;
    }

    public alumnos getNalumno() {
        return nalumno;
    }

    public void setNalumno(alumnos nalumno) {
        this.nalumno = nalumno;
    }

    public Proyectos getNproyecto() {
        return nproyecto;
    }

    public void setNproyecto(Proyectos nproyecto) {
        this.nproyecto = nproyecto;
    }

    public Directores getNdirector() {
        return ndirector;
    }

    public void setNdirector(Directores ndirector) {
        this.ndirector = ndirector;
    }

}
